//
//  NewsFooterView.m
//  ZYHome
//
//  Created by Teplot_03 on 16/7/6.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "NewsFooterView.h"
#import "VerticalSepLine.h"

@interface NewsFooterView ()

@property (nonatomic, strong) VerticalSepLine *sepLine;

@end
@implementation NewsFooterView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup {
    self.backgroundColor = LightGray_Color;
    [self addSubview:self.leftBtn];
    [self addSubview:self.rightBtn];
    [self addSubview:self.sepLine];
    
    _leftBtn.sd_layout.leftEqualToView(self)
    .widthRatioToView(self,0.499)
    .topSpaceToView(self,0.5)
    .bottomSpaceToView(self,0.5);
    
    _rightBtn.sd_layout.rightEqualToView(self)
    .widthRatioToView(self,0.5)
    .topSpaceToView(self,0.5)
    .bottomSpaceToView(self,0.5);
    
    _sepLine.sd_layout
    .leftSpaceToView(_leftBtn,0)
    .rightSpaceToView(_rightBtn,0)
    .topSpaceToView(self,0.5)
    .bottomSpaceToView(self,0.5);
}

#pragma mark - buttonClick
- (void)buttonClicked:(UIButton *)sender {
    
    BOOL isLeft = sender == _leftBtn;
    if ([self.delegate respondsToSelector:@selector(newsFooterView:indexOfClicked:)]) {
        [self.delegate newsFooterView:self indexOfClicked:isLeft?0:1];
    }
}

#pragma mark - lazy load
- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftBtn.backgroundColor = [UIColor whiteColor];
        [_leftBtn setImage:[UIImage imageNamed:@"photo"] forState:UIControlStateNormal];
        [_leftBtn setTitleColor:RGBCOLOR(73, 73, 73) forState:UIControlStateNormal];
        [_leftBtn setTitle:@"  插入图片" forState:UIControlStateNormal];
        [_leftBtn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftBtn;
}

- (UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightBtn.backgroundColor = [UIColor whiteColor];
        [_rightBtn setImage:[UIImage imageNamed:@"text"] forState:UIControlStateNormal];
        [_rightBtn setTitle:@"  插入文字" forState:UIControlStateNormal];
        [_rightBtn setTitleColor:RGBCOLOR(73, 73, 73) forState:UIControlStateNormal];
        [_rightBtn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightBtn;
}

- (VerticalSepLine *)sepLine {
    if (!_sepLine) {
        _sepLine = [[VerticalSepLine alloc] init];
    }
    return _sepLine;
}

@end
